package scct.zhanghongbo.utils;

import java.sql.*;

public class DBUtils {
    private static final String url = "jdbc:mysql://localhost:3306/crdb?serverTimezone=GMT%2B8&characterEncoding=utf8&useSSL=true";
    private static final String user = "root";
    private static final String password = "123456";
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    public static Connection getConnection() {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, user, password);
        }catch (SQLException e){
            throw new RuntimeException(e);
        }
        return conn;
    }
    public static void close(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            }catch (SQLException e){
                throw new RuntimeException(e);
            }finally {
                conn = null;
            }
        }
    }
}
